<template>
    <el-row class="edit">
        <el-container style="height: 100%;">
            <el-header height="60px">
                修改区域
            </el-header>
            <el-main>
                <el-form ref="addYardData" :rules="rules" :model="addYardData" label-width="115px"
                         label-position="left">
                    <el-form-item label="区域名称 :" prop="name">
                        <el-input v-model="addYardData.name" placeholder="请输入区域名称"></el-input>
                    </el-form-item>
                    <el-form-item label="区域编码 :" prop="code">
                        <el-input v-model="addYardData.code" placeholder="请输入区域编码"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用 :" prop="enabled">
                        <el-radio-group v-model="addYardData.enabled">
                            <el-radio :label="true">启用</el-radio>
                            <el-radio :label="false">不启用</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="是否可见 :" prop="visible">
                        <el-radio-group v-model="addYardData.visible">
                            <el-radio :label="true">可见</el-radio>
                            <el-radio :label="false">不可见</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="父级名称">
                        <el-row>{{addYardData.patName}}</el-row>
                    </el-form-item>
                </el-form>
            </el-main>
            <el-footer height="80px">
                <el-row style="height: 20px;margin-bottom: 5px;">
                    <transition name="el-zoom-in-bottom">
                        <el-row v-show="infoShow" style="display: flex;justify-content: center;align-items: center;">
                            {{ (info !== '') ? "提示信息："+info : ''}}
                        </el-row>
                    </transition>
                </el-row>

                <el-row style="display: flex;justify-content: center;align-items: center;">
                    <el-button @click="submit" type="primary">
                        保存
                    </el-button>
                    <el-button @click="editOut">
                        取消
                    </el-button>
                </el-row>
            </el-footer>
        </el-container>
    </el-row>
</template>

<script>
    import {replaceSpacesObj} from '../../utils/webUtils.js';

    export default {
        name: "editMenu",
        data() {
            return {
                formAlignLeft: 'left',
                uuid: this.yardUuid,
                addYardData: {},
                rules: {
                    name: [
                        {required: true, message: '区域名称不得为空', trigger: 'blur'},
                    ],
                    code: [
                        {required: true, message: '区域编码不得为空', trigger: 'blur'},
                    ]
                },
                info: '',
                infoShow: false
            }
        },
        props: {
            yardUuid: {
                type: String
            }
        },
        //深度监听父组件的props传值
        watch: {
            yardUuid(val) {
                this.uuid = val;
                this.queryYard();
            }
        },
        mounted() {
            this.queryYard();
        },
        methods: {
            queryYard() {
                this.axios.request({
                    method: "get",
                    url: "./ope/kdi/yard/" + this.uuid,
                    headers: {},
                    params: {}
                }).then(response => {
                    this.addYardData = response.data;
                }).catch(error => {
                    console.log(error);
                });
            },
            submit() {
                this.$refs['addYardData'].validate((valid) => {
                    if (!valid) {
                        return;
                    }
                    this.axios.request({
                        method: "put",
                        url: "./ope/kdi/yard/" + this.uuid,
                        headers: {
                            "Content-Type": "application/json;charset=UTF-8"
                        },
                        data: replaceSpacesObj(this.addYardData)
                    }).then(() => {
                        this.info = '修改成功,两秒后关闭';
                        this.infoShow = true;
                        setTimeout(() => {
                            this.infoShow = false;
                            this.$emit("editState", false);
                            this.info = '';
                        }, 2000);
                    }).catch(error => {
                        console.log(error);
                        this.info = "修改失敗";
                        this.infoShow = true;
                    });
                });
            },
            editOut() {
                this.infoShow = false;
                this.info = '';
                this.$emit("editState", false);
            }
        }
    }
</script>

<style scoped>
    .edit {
        width: 334px;
        height: 100%;
        z-index: 100;
    }


</style>